package com.atguigu.lease.admin.controller.lease;

import com.atguigu.lease.admin.service.ViewAppointmentService;
import com.atguigu.lease.common.result.Result;
import com.atguigu.lease.model.bean.ViewAppointment;
import com.atguigu.lease.model.vo.lease.AppointmentItemVo;
import com.atguigu.lease.model.vo.lease.AppointmentQueryVo;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

/**
 * @author LOGIN
 * @title AppointmentController
 * @create 2025/6/27 8:49
 * @description
 */
@Tag(name = "租约管理-预约看房管理")
@RestController
@RequestMapping("/admin/appointment")
public class AppointmentController {
    @Resource
    ViewAppointmentService viewAppointmentService;
//    /admin/appointment/updateStatusById?id=11&status=3
    @Operation(summary = "2、根据id更新预约状态")
    @PostMapping("updateStatusById")
    public Result updateStatusById(@RequestParam Long id,@RequestParam String status){
        viewAppointmentService.update(Wrappers.lambdaUpdate(ViewAppointment.class)
                .eq(ViewAppointment::getId, id)//查找要修改状态记录对应的id
                .set(ViewAppointment::getAppointmentStatus,status));//修改看房状态
        return Result.ok();
    }

    @Operation(summary = "1、分页查询预约信息")
    @GetMapping("/page")
    public Result<Page<AppointmentItemVo>> page(@RequestParam Long current,
                                                   @RequestParam Long size,
                                                    AppointmentQueryVo queryVo){
        Page<AppointmentItemVo> page = viewAppointmentService.pageItem(current,size,queryVo);
        return  Result.ok(page);
    }

}
